<?php
class Helper_paylogexcel
{
	public static function agentMoneyLog($acct,$closeLog)
	{
		$startTime = $closeLog->starttime;
		$endTime = $closeLog->created;
		$closeData = closemoneylog::find('oper_id = ? AND created >= ? AND created<?',$acct->id,$startTime,$endTime)->getAll();
		$filename = sprintf("%s(%s)",$acct->nickname,$acct->username);
		$savePath = Q::ini('app_config/ROOT_DIR').'/log/';
		require_once('../lib/Classes/PHPExcel.php');
		require_once('../lib/Classes/PHPExcel/Writer/Excel2007.php');
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);
		
		//设置样式
		$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A1');
		$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objFontA1 = $objStyleA1->getFont();
		$objFontA1->setName('宋体');
		$objFontA1->setSize(14);
		$objFontA1->setBold(true);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(24);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A1', "{$filename}_对账单");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->setCellValue('A2', "{$filename}");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('B2:E2');
		
		//$pre_closeTime = $startTime == 0 ? '未结账':date('Y-m-d H:i:s',$startTime);
		//$objPHPExcel->getActiveSheet()->setCellValue('B2', "上次结账: ".$pre_closeTime);//可以指定位置
		
		//$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		//$objPHPExcel->getActiveSheet()->mergeCells('D2:E2');
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('B2', "本次结账: ".date('Y-m-d H:i:s',$startTime).'-'.date('Y-m-d H:i:s',$endTime));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->mergeCells('A3:E3');
		$objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A4', "总计");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B4', "结账总额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('C4', abs($closeLog->closemoney));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('C4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D4', "实收金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('D4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('E4', abs($closeLog->cash));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('E4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A5', "");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B5', "结账前余额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('C5', ($closeLog->pre_balance));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('C5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D5', "结账后余额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('D5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('E5', $closeLog->closemoney+$closeLog->pre_balance);//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('E5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A6', "操作类型");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('B6', "金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('C6', "结账商家");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('D6', "操作日期");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('E6', "来源");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('B6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('C6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('D6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('E6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$lineNub = 7;
		
		foreach ($closeData as $k=>$v)
		{
			$org = "商家结账";
			
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("%.2f",$v->closemoney));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->acct_name);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,'为商家结账');
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$lineNub+= 1;
		}
		require_once('../lib/Classes/PHPExcel/Writer/Excel5.php');
		$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
		$realFile = $savePath.$acct->username.'.xls';
		$objWriter->save($realFile);
		return $realFile;
	}
	
	public static function closeMoneyToExcel($acct,$closeLog)
	{
		$startTime = $closeLog->starttime;
		$endTime = $closeLog->created;
		$transferData = transferlog::find('agent_id = ? AND created>= ? AND created < ? ',$acct->id,$startTime,$endTime)->getAll();
		$payData = mzcardlog::find('agent_id = ? AND created>= ? AND created< ? AND modetype = 1',$acct->id,$startTime,$endTime)->order('id asc')->getAll();
		//$taobaoLog = mztblog::find('acct_id = ? AND created = ?',$acct->id,$endTime)->getAll();
		$closeMoneyLog = closemoneylog::find('oper_id = ? AND created>= ? AND created< ?',$acct->id,$startTime,$endTime)->getAll();
		$rollbackData = rollbackuserlog::find('rollback_agentid = ? AND created >= ? AND created<?',$acct->id,$startTime,$endTime)->order('id asc')->getAll();
		$filename = sprintf("%s(%s)",$acct->nickname,$acct->username);
		$savePath = Q::ini('app_config/ROOT_DIR').'/log/';
		require_once('../lib/Classes/PHPExcel.php');
		require_once('../lib/Classes/PHPExcel/Writer/Excel2007.php');
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);
		
		//设置样式
		$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A1');
		$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objFontA1 = $objStyleA1->getFont();
		$objFontA1->setName('宋体');
		$objFontA1->setSize(14);
		$objFontA1->setBold(true);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(24);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A1', "{$filename}_对账单");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->setCellValue('A2', "{$filename}");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('B2:E2');
		
		//$pre_closeTime = $startTime == 0 ? '未结账':date('Y-m-d H:i:s',$startTime);
		//$objPHPExcel->getActiveSheet()->setCellValue('B2', "上次结账: ".$pre_closeTime);//可以指定位置
		
		//$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		//$objPHPExcel->getActiveSheet()->mergeCells('D2:E2');
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('B2', "本次结账: ".date('Y-m-d H:i:s',$startTime).'-'.date('Y-m-d H:i:s',$endTime));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->mergeCells('A3:E3');
		$objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A4', "总计");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B4', "结账总额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('C4', abs($closeLog->closemoney));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('C4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D4', "实收金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('D4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('E4', abs($closeLog->cash));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('E4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		

		$objPHPExcel->getActiveSheet()->setCellValue('A5', "");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B5', "结账前余额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('C5', ($closeLog->pre_balance));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('C5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D5', "结账后余额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('D5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('E5', $closeLog->closemoney+$closeLog->pre_balance);//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('E5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A6', "操作类型");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('B6', "金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('C6', "充值号码");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('D6', "操作日期");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('E6', "来源");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->getStyle('A6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('B6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('C6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('D6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('E6')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		
		$lineNub = 7;
		
		foreach ($transferData as $k=>$v)
		{
			$org = "充值卡划拨";
			if($v->cardbalance>0)$org="充值卡回收";
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,$v->ispay == 1 ?sprintf("%.2f",$v->cardbalance):0);
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->agent_name);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,$v->oper_agentname.'-划拨');
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$lineNub+= 1;
		}
		
		foreach ($payData as $k=>$v)
		{
			$org = "空中充值";
		
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("-%.2f",$v->balance));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->username);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"空充");
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				
			$lineNub+= 1;
		}
		foreach ($rollbackData as $k=>$v)
		{
			$org = "退卡";
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("%.2f",$v->backmoney));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->voip_acctname);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"系统");
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$lineNub+= 1;
		}
		
// 		foreach ($taobaoLog as $k=>$v)
// 		{
// 			$org = "淘宝结账";
// 			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
// 			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("%.2f",$v->money));
// 			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->username);
// 			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
// 			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"淘宝-".$v->buyer_nick.'-'.$v->orderid);
// 			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
// 			$lineNub+= 1;
// 		}
		
		foreach ($closeMoneyLog as $k=>$v)
		{
			$org = "划出余额";
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("-%.2f",$v->closemoney));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->acct_name);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"划出->".$v->acct_name);
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$lineNub+= 1;
		}
		
		require_once('../lib/Classes/PHPExcel/Writer/Excel5.php');
		$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
		$realFile = $savePath.$acct->username.'.xls';
		$objWriter->save($realFile);
		return $realFile;
	}
	
	/**
	 * 
	 * @param acct $acct
	 */
	public static function toexcel($acct)
	{
		$startTime = $acct->pre_moneytime;
		$endTime = time();
		$transferData = transferlog::find('agent_id = ? AND created>= ? AND created < ? ',$acct->id,$startTime,$endTime)->getAll();
		$payData = mzcardlog::find('agent_id = ? AND created>= ? AND created< ? AND modetype = 1',$acct->id,$startTime,$endTime)->order('id asc')->getAll();
		//$taobaoLog = tblog::find('acct_id = ? AND created = ?',$acct->id,$endTime)->getAll();
		$closeMoneyLog = closemoneylog::find('(oper_id = ? OR acct_id = ?) AND created>= ? AND created< ?  ',$acct->id,$acct->id,$startTime,$endTime)->getAll();
		
		$rollbackData = rollbackuserlog::find('rollback_agentid = ? AND created >= ? AND created<?',$acct->id,$startTime,$endTime)->order('id asc')->getAll();
		$filename = sprintf("%s(%s)",$acct->nickname,$acct->username);
		$savePath = Q::ini('app_config/ROOT_DIR').'/log/';
		require_once('../lib/Classes/PHPExcel.php');
		require_once('../lib/Classes/PHPExcel/Writer/Excel2007.php');
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);
		
		//设置样式
		$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A1');
		$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objFontA1 = $objStyleA1->getFont();
		$objFontA1->setName('宋体');
		$objFontA1->setSize(14);
		$objFontA1->setBold(true);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(24);
		
		//$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(24);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('A1:E1');
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A1', "{$filename}_对账单");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->setCellValue('A2', "{$filename}");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->mergeCells('B2:E2');
		
		//$pre_closeTime = $startTime == 0 ? '未结账':date('Y-m-d H:i:s',$startTime);
		//$objPHPExcel->getActiveSheet()->setCellValue('B2', "上次结账: ".$pre_closeTime);//可以指定位置
		
		//$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		//$objPHPExcel->getActiveSheet()->mergeCells('D2:E2');
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('B2', "本次结账: ".date('Y-m-d H:i:s',$startTime).'-'.date('Y-m-d H:i:s',$endTime));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->mergeCells('A3:E3');
		$objPHPExcel->getActiveSheet()->getStyle('A3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A4', "总计");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('A4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B4', "当前余额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('B4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('C4', ($acct->balance));//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('C4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$objPHPExcel->getActiveSheet()->setCellValue('D4', "应缴金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('D4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		$money = "";
		if( abs($acct->payrate)<0.8)
		{
			$money = "请设置此代理的折扣,必须大于等于1折";
		}else if ($acct->balance>0){
			$money = "0";
		}else{
			$money = sprintf("%.2f",abs($acct->balance)*(($acct->payrate/10))) ;
		}
		$objPHPExcel->getActiveSheet()->setCellValue('E4', $money);//可以指定位置
		$objPHPExcel->getActiveSheet()->getStyle('E4')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		

// 		$objPHPExcel->getActiveSheet()->setCellValue('A5', "");//可以指定位置
// 		$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
// 		$objPHPExcel->getActiveSheet()->setCellValue('B5', "结账前余额");//可以指定位置
// 		$objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
// 		$objPHPExcel->getActiveSheet()->setCellValue('C5', ($closeLog->pre_balance));//可以指定位置
// 		$objPHPExcel->getActiveSheet()->getStyle('C5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
// 		$objPHPExcel->getActiveSheet()->setCellValue('D5', "结账后余额");//可以指定位置
// 		$objPHPExcel->getActiveSheet()->getStyle('D5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
// 		$objPHPExcel->getActiveSheet()->setCellValue('E5', $closeLog->closemoney+$closeLog->pre_balance);//可以指定位置
// 		$objPHPExcel->getActiveSheet()->getStyle('E5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		$objPHPExcel->getActiveSheet()->setCellValue('A5', "操作类型");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('B5', "金额");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('C5', "充值号码");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('D5', "操作日期");//可以指定位置
		$objPHPExcel->getActiveSheet()->setCellValue('E5', "来源");//可以指定位置
		
		$objPHPExcel->getActiveSheet()->getStyle('A5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('B5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('C5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('D5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->getStyle('E5')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
		
		
		
		$lineNub = 6;
		
		foreach ($transferData as $k=>$v)
		{
			$org = "充值卡划拨";
			if($v->cardbalance>0)$org="充值卡回收";
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,$v->ispay == 1 ? sprintf("%.2f",$v->cardbalance) : 0);
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->agent_name);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,$v->oper_agentname.'-划拨('.$v->cardnum.'张)');
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		
			$lineNub+= 1;
		}
		
		foreach ($payData as $k=>$v)
		{
			$org = "空中充值";
		
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("-%.2f",$v->balance));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->username);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"微信");
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
				
			$lineNub+= 1;
		}
		foreach ($rollbackData as $k=>$v)
		{
			$org = "退卡";
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,sprintf("%.2f",$v->backmoney));
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->voip_acctname);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,"系统");
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$lineNub+= 1;
		}

		foreach ($closeMoneyLog as $k=>$v)
		{
			$org = "划出余额";
			if($acct->id == $v->acct_id)
				{
					$org = "划入余额";
					$balance = abs((sprintf("%.2f",$v->closemoney)));
				}else if($acct->id == $v->oper_id){
					$org = "划出余额";
					$balance = ((sprintf("-%.2f",abs($v->closemoney))));
				}
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$lineNub,$balance);
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$lineNub,$v->acct_name);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$lineNub,date('Y-m-d H:i:s',$v->created));
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$lineNub,$org);
			$objPHPExcel->getActiveSheet()->getStyle('A'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('B'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('C'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('D'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objPHPExcel->getActiveSheet()->getStyle('E'.$lineNub)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$lineNub+= 1;
		}
		require_once('../lib/Classes/PHPExcel/Writer/Excel5.php');
		$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
		$realFile = $savePath.$acct->username.'.xls';
		$objWriter->save($realFile);
		return $realFile;
	}
    static function generateuserslogxls($title,$titlekey,$width,$data,$height){
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel.php');
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel/Writer/Excel2007.php');
	
	
	    $objPHPExcel = new PHPExcel();
	
	    $objPHPExcel->setActiveSheetIndex(0);
	    $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight($height);
	    foreach($title as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue($k,$v);
	        $col = substr($k, 0,1);
	        $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setWidth($width);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle($k);
	        $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	        $objFontA1 = $objStyleA1->getFont();
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(12);
	
	        $objPHPExcel->getActiveSheet()->getStyle($col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	    }
	    $i=2;
	    // $letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
	    foreach($data as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$v['day']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('F'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	        $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$v['total_sale']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v['user_rewardsale']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$v['user_totalwithdraw']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('D'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$v['user_unwithdraw']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$v['lirun']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('F'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	        $i++;
	    }
	    $filename = $titlekey.'_'.date('Y-m-dHis');
	    header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
	    header('Content-Disposition: attachment;filename="'.$filename.'_Excel.xls"');
	    header('Cache-Control: max-age=0');
	    $objWriter =  PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	    $objWriter -> save('php://output');
	
	}
    static function generatewithdrwalogxls($title,$titlekey,$width,$data,$height){
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel.php');
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel/Writer/Excel2007.php');
	
	
	    $objPHPExcel = new PHPExcel();
	
	    $objPHPExcel->setActiveSheetIndex(0);
	    $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight($height);
	    foreach($title as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue($k,$v);
	        $col = substr($k, 0,1);
	        $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setWidth($width);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle($k);
	        $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	        $objFontA1 = $objStyleA1->getFont();
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(12);
	
	        $objPHPExcel->getActiveSheet()->getStyle($col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	    }
	    $i=2;
	    // $letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
	    foreach($data as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$v['username']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v['withdraw_money']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('C'.$i," ".$v['bank_card']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('C'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$v['bank_account']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('D'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$v['bank_openadd']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$v['apply_status']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('F'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('G'.$i,$v['created']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('G'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	         
	        $i++;
	    }
	    $filename = $titlekey.'_'.date('Y-m-dHis');
	    header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
	    header('Content-Disposition: attachment;filename="'.$filename.'_Excel.xls"');
	    header('Cache-Control: max-age=0');
	    $objWriter =  PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	    $objWriter -> save('php://output');
	
	}
    static function generaterewardlogxls($title,$titlekey,$width,$data,$height){
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel.php');
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel/Writer/Excel2007.php');
	
	
	    $objPHPExcel = new PHPExcel();
	
	    $objPHPExcel->setActiveSheetIndex(0);
	    $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight($height);
	    foreach($title as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue($k,$v);
	        $col = substr($k, 0,1);
	        $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setWidth($width);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle($k);
	        $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	        $objFontA1 = $objStyleA1->getFont();
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(12);
	
	        $objPHPExcel->getActiveSheet()->getStyle($col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	    }
	    $i=2;
	    // $letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
	    foreach($data as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValueExplicit('A'.$i,$v['order_id'],PHPExcel_Cell_DataType::TYPE_STRING);
//            dump($v['order_id']);die;
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v['username']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$v['oldbalance']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('C'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$v['payfee']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('D'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$v['balance_voucher']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	        $objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$i,$v['trade_no'],PHPExcel_Cell_DataType::TYPE_STRING);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('F'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
            $objPHPExcel->getActiveSheet()->setCellValue('G'.$i,$v['pay_time']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('G'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	        $i++;
	    }
        ob_end_clean();
	    $filename = $titlekey.'_'.date('Y-m-dHis');
	    header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
	    header('Content-Disposition: attachment;filename="'.$filename.'_Excel.xls"');
	    header('Cache-Control: max-age=0');
        
	    $objWriter =  PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	    $objWriter -> save('php://output');
	
	}
    
    static function generatevoucherlogxls($title,$titlekey,$width,&$data,$height){
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel.php');
	    require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel/Writer/Excel2007.php');
	
	
	    $objPHPExcel = new PHPExcel();
	
	    $objPHPExcel->setActiveSheetIndex(0);
	    $objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight($height);
	    foreach($title as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue($k,$v);
	        $col = substr($k, 0,1);
	        $objPHPExcel->getActiveSheet()->getColumnDimension($col)->setWidth($width);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle($k);
	        $objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	        $objFontA1 = $objStyleA1->getFont();
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(12);
	
	        $objPHPExcel->getActiveSheet()->getStyle($col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	    }
	    $i=2;
	    // $letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q');
	    foreach($data as $k=>$v){
	        $objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$v['id']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v['username']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('C'.$i," ".$v['parent_username']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('C'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$v['payfee']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('D'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(11);
	        $objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$v['created']);
	        $objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
	        $objFontA1->setName('宋体');
	        $objFontA1->setSize(10);
	         
	        $i++;
	    }
	    $filename = $titlekey.'_'.date('Y-m-dHis');
      //  dump($filename);die;
	    header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
	    header('Content-Disposition: attachment;filename="'.$filename.'_Excel.xls"');
	    header('Cache-Control: max-age=0');
	    $objWriter =  PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
	    $objWriter -> save('php://output');
	
	}


	static function userinfoexecl($title,$titlekey,$width,&$data,$height){
		require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel.php');
		require_once(Q::ini('app_config/ROOT_DIR').'/lib/Classes/PHPExcel/Writer/Excel2007.php');
		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);
		$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight($height);
		foreach($title as $k=>$v){
			$objPHPExcel->getActiveSheet()->setCellValue($k,$v);
			$col = substr($k, 0,1);
			$objPHPExcel->getActiveSheet()->getColumnDimension($col)->setWidth($width);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle($k);
			$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			$objFontA1 = $objStyleA1->getFont();
			$objFontA1->setName('宋体');
			$objFontA1->setSize(12);
			$objPHPExcel->getActiveSheet()->getStyle($col)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		}
		$i=2;
		foreach($data as $k=>$v){
			$objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$v['username']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('A'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$v['total_consume']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('B'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$v['commission']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('C'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$v['used_commission']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('D'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$v['wait_commission']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$v['type']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('G'.$i,$v['viplevel_id']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('H'.$i,$v['due_time']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('I'.$i,$v['phone']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('J'.$i,$v['id_card_num']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('K'.$i,$v['real_name']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('L'.$i,$v['do_day']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('M'.$i,$v['today_dolog_num']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('N'.$i,$v['today_avg_right_per']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('O'.$i,$v['dolog_num']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('P'.$i,$v['avg_right_per']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('Q'.$i,$v['my_video_num']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('R'.$i,$v['avg_right_per']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('S'.$i,$v['qinshang']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('T'.$i,$v['my_v_sort']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$objPHPExcel->getActiveSheet()->setCellValue('U'.$i,$v['learn_num']);
			$objStyleA1 = $objPHPExcel->getActiveSheet()->getStyle('E'.$i);
			$objFontA1->setName('宋体');
			$objFontA1->setSize(11);
			$i++;
		}
		$filename = $titlekey.'_'.date('Y-m-dHis');
		header('Content-Type: application/vnd.ms-excel;charset=UTF-8');
		header('Content-Disposition: attachment;filename="'.$filename.'_Excel.xls"');
		header('Cache-Control: max-age=0');
		$objWriter =  PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter -> save('php://output');
	}
    
}